<script setup lang="ts">
import { ref } from 'vue';
import { getCurrentInstance, redirectTo, showLoading, hideLoading } from '@tarojs/taro';
import { LOGIN_APP } from '/@/api/modules/base/app-sys-user';
import { RESUME_APP_TASK } from '/@/api/modules/order/app-work-order';
import { formState } from './state';

/**
 * @description 当前路由信息
 */
const params = getCurrentInstance().router?.params as {
  id: string;
};

const workOrderResumeForm = ref();

function submit() {
  showLoading();
  LOGIN_APP().then((res) => {
    formState.workOrderDto.id = params.id;
    formState.workOrderEventDto.workOrderId = params.id;
    formState.workOrderEventDto.handleUserId = res.sysUserDto.id;
    formState.workOrderEventDto.handleUserName = res.sysUserDto.name;
    formState.workOrderEventDto.handleTime = new Date().valueOf();

    RESUME_APP_TASK(formState).then(() => {
      formState.workOrderEventDto = {
        workOrderId: '',
        handleUserId: '',
        handleUserName: '',
        handleTime: undefined,
        opinion: '',
        workOrderEventFileDto: [],
      };
      formState.workOrderDto = {
        id: '',
        workOrderPreAssetDto: [],
      };
      hideLoading();
      redirectTo({
        url: `/pages/work-order/resume-success/index?id=${params.id}`,
      });
    });
  });
}
</script>

<template>
  <view class="work-order-resume app-page--1">
    <app-navbar title="解挂" />
    <scroll-view class="app-page__wrapper" :scroll-y="true" :lower-threshold="100">
      <view class="work-order-resume__wrapper">
        <nut-form
          :model-value="formState"
          class="work-order-resume__form"
          ref="workOrderResumeForm"
        >
          <nut-form-item class="nut-form__title-wrapper" label="解挂意见" />
          <nut-form-item>
            <nut-textarea
              v-model="formState.workOrderEventDto.opinion"
              placeholder="请输入解挂意见"
              rows="8"
              limit-show
              text-align="left"
              max-length="200"
            />
          </nut-form-item>
          <nut-form-item>
            <view class="work-order-resume__quick-reply-wrapper">
              <view class="work-order-resume__quick-reply-wrapper--left">
                <text>快速回复:</text>
              </view>
              <view class="work-order-resume__quick-reply-wrapper--right">
                <nut-button
                  class="work-order-resume__btn"
                  v-for="item in [{ key: '1', label: '当前具备处理条件' }]"
                  :key="item.key"
                  type="default"
                  size="mini"
                  @click="
                    () => {
                      formState.workOrderEventDto.opinion = item.label;
                    }
                  "
                >
                  {{ item.label }}
                </nut-button>
              </view>
            </view>
          </nut-form-item>
        </nut-form>
      </view>
    </scroll-view>
    <view class="work-order-resume__footer">
      <nut-button block type="info" @click="submit">
        <text>提交</text>
      </nut-button>
    </view>
  </view>
</template>

<style lang="scss">
@import './index.scss';
</style>
